using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using WP.Commons;
using System.Collections;
using WP.DB;
using WP.Controls;
namespace WP.Modules
{
    public partial class frmUIDesign : BaseQryRpt 
    {

        //private declare function getversionex lib "kernel32" alias "getversionexa" (lpversioninformation as osversioninfo) as long 

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;
        private string mstrCurrentStyle = "Default";
        private Control mCurrentControl = null;
        private enum DtlColumn { PropertyName = 0, PropertyValue,ControlName, ValueChanged }
        private enum DtlRow { Text = 0, Visible, Enabled, Left, Top, Width, Height, Backcolor, Forecolor, DefaultValue, Help,IsSystemField,SpecialString,SpecialColor, RowsCount }
        private string mstrProgName = "",mstrTable="";
        private int miParameter = 0, miLastDtlRowIndex=0;
        private MenuInfo mCurrentMenuInfo;
        private bool mbCanTrigerCellValueChangedEven = false;
        private FormStatus mformStatus = FormStatus.AddNew; 
        private struct ControlProperty{
            public  Control Control;
            public Point Location;
            public Size Size;
            public bool Visble;
            public bool Enable;
            public bool IsSystemField;
            public string SpecialString;
            public Color SpecialColor;
            public string Text;
            public string Help;
            public string DefaultValue;
            public Color BackColor;
            public Color ForeColor;
        };
        private ControlAttribute[] OldProperty, NewProperty, DefProperty;
       // private  ControlProperty[] OldProperty,NewProperty,DefProperty;
        public frmUIDesign()
        {
            InitializeComponent();

        }

        private void tbnExit_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }
        private FormStatus Status
        {
            get 
            {
                return mformStatus; 
            }
            set
            {
                mformStatus = value;
                switch (mformStatus)
                {
                    case FormStatus.AddNew :
                        tbnDel.Enabled = false;
                        tbnSave.Enabled = true; 
                        tbnOpen.Enabled =true ;
                        tbnNew.Enabled = true;

                        tbnUserStyle.Enabled = true ; 
                        
                        break;
                    case FormStatus.Delete :
                        tbnDel.Enabled = false ;
                        tbnSave.Enabled = false ;
                        tbnOpen.Enabled = true;
                        tbnNew.Enabled = true;

                        tbnUserStyle.Enabled = false; 
                        foreach (Form f in this.MdiChildren)
                        {
                            f.Close();
                        }

                        this.Text = "User Interface Design";
                        this.cboSeleControl.Text = "";
                        
                        break;
                    case FormStatus.Update :
                        tbnDel.Enabled = true ;
                        tbnSave.Enabled = true;
                        tbnOpen.Enabled = true;
                        tbnNew.Enabled = true;

                        tbnUserStyle.Enabled = true; 
                        break;
                 }

                 this.deleteToolStripMenuItem.Enabled = tbnDel.Enabled && tbnDel.Visible;
                 this.saveToolStripMenuItem.Enabled = tbnSave.Enabled && tbnSave.Visible;
                 this.openToolStripMenuItem.Enabled = tbnOpen.Enabled && tbnOpen.Visible;
                 this.newToolStripMenuItem.Enabled = tbnNew.Enabled && tbnNew.Visible;
                 this.userStyleToolStripMenuItem.Enabled = tbnUserStyle.Enabled && tbnUserStyle.Visible;
  
            }
        }

        public void SetUI(MenuInfo menuinfo, string strTable)
        {
            SetUI(menuinfo, strTable, "");
        }
        public void SetUI(MenuInfo menuinfo, string strTable,string strDesignStyle)
        {
            foreach (Form f in this.MdiChildren)
            {
                f.Close();
            }

            
            mCurrentMenuInfo = menuinfo;
            DBAccess dbcon = new DBAccess(false, false);
            DataView dvUserDefUiStyle = dbcon.GetDataTable("select * from mUIUserStyle where userName='" + SysVar.UserName + "' and checked=1 and progname='" + mCurrentMenuInfo.strProgname + "' and Parameter=" + mCurrentMenuInfo.iParameter.ToString()).DefaultView;
            if (dvUserDefUiStyle.Count > 0)
            {
                dbcon.ExecuteSql("Update mUIUserStyle set checked=0 where userName='" + SysVar.UserName + "' and progname='" + mCurrentMenuInfo.strProgname + "' and Parameter=" + mCurrentMenuInfo.iParameter.ToString());
            }
            Size sizeNormal;
            Form frmobj = ReflectMethod.GetForm(mCurrentMenuInfo, false,  out sizeNormal, out strTable);
            if (dvUserDefUiStyle.Count > 0)
            {
                dbcon.ExecuteSql("Update mUIUserStyle set checked=1 where UiStyle='" + dvUserDefUiStyle[0]["UIStyle"].ToString().Replace("'", "''") + "' and userName='" + SysVar.UserName + "' and progname='" + mCurrentMenuInfo.strProgname + "' and Parameter=" + mCurrentMenuInfo.iParameter.ToString());
            }
            dbcon.CloseCon();  
            if (frmobj == null) return;

            frmobj.Text = mCurrentMenuInfo.strMenuName;

            mstrProgName = frmobj.Name;
            miParameter = menuinfo.iParameter ;
            mstrTable = strTable;
            mstrCurrentStyle = strDesignStyle == "" ? "Default" : strDesignStyle;

            this.Text = "User Interface Design" ;
            System.Windows.Forms.Form frmNew = new System.Windows.Forms.Form();
            frmobj.WindowState = FormWindowState.Normal;
           
            frmNew.Size = sizeNormal;
            frmNew.Text = frmobj.Text +"- [" + (mstrCurrentStyle == "Default" ? "Untitled1" : mstrCurrentStyle) + "]";
            arraycontrols.Clear();
            foreach (Control con in frmobj.Controls)
            {
                AddControl(frmNew, con);
            }
            arraycontrols.TrimToSize();
            OldProperty = new ControlAttribute[arraycontrols.Count];
            NewProperty = new ControlAttribute[arraycontrols.Count];
            DefProperty = new ControlAttribute[arraycontrols.Count];
            for (int i = 0; i < arraycontrols.Count; i++)
            {
                OldProperty[i] = new ControlAttribute();
                NewProperty[i] = new ControlAttribute();
                DefProperty[i] = new ControlAttribute();
            }



            GetOldAndDefaultProperty();
            for (int i = 0; i < OldProperty.Length; i++)
            {
                NewProperty[i].BackColor = OldProperty[i].BackColor;
                NewProperty[i].Control = OldProperty[i].Control;
                NewProperty[i].DefaultValue = OldProperty[i].DefaultValue;
                NewProperty[i].Enable = OldProperty[i].Enable;
                NewProperty[i].ForeColor = OldProperty[i].ForeColor;
                NewProperty[i].Help = OldProperty[i].Help;
                NewProperty[i].IsSystemField = OldProperty[i].IsSystemField;
                NewProperty[i].Location = OldProperty[i].Location;
                NewProperty[i].Size = OldProperty[i].Size;
                NewProperty[i].SpecialColor = OldProperty[i].SpecialColor;
                NewProperty[i].SpecialString = OldProperty[i].SpecialString;
                NewProperty[i].Text = OldProperty[i].Text;
                NewProperty[i].Visble = OldProperty[i].Visble;

            }
            frmNew.Location = new Point(0, 0); 
            frmNew.MdiParent = this;
            frmobj.Close();
            frmNew.FormClosed += new FormClosedEventHandler(this.ChildForm_Closed);
            this.pnlRight.Width = 281;
            frmNew.Show();
            frmNew.Refresh(); 
            this.Show();
            this.Refresh();
            
        }

        private bool ConfirmChanged()
        {
            bool blnSameAsDefaultProperty;
            foreach (Control con in arraycontrols)
            {
                if (ControlPropertyChanged(con, out blnSameAsDefaultProperty)) return true;
            }
            return false;
        }


        private  bool ControlPropertyChanged(Control con ,out bool blnSameAsDefaultProperty)
        {
            ControlAttribute oldfinfo = GetOldContorlProptyInfo(con.Name);
            ControlAttribute newfinfo = GetNewContorlProptyInfo(con.Name);
            ControlAttribute Deffinfo = GetDefControlProptyInfo(con.Name);
            blnSameAsDefaultProperty = false;
            if (Deffinfo.Control != null && newfinfo.Control != null && Deffinfo.Control.Name == newfinfo.Control.Name &&
                Deffinfo.BackColor == newfinfo.BackColor &&
                Deffinfo.ForeColor == newfinfo.ForeColor &&
                Deffinfo.DefaultValue == newfinfo.DefaultValue &&
                Deffinfo.Enable == newfinfo.Enable &&
                Deffinfo.Help == newfinfo.Help &&
                Deffinfo.IsSystemField == newfinfo.IsSystemField &&
                Deffinfo.Location == newfinfo.Location &&
                Deffinfo.Size == newfinfo.Size &&
                Deffinfo.Text == newfinfo.Text &&
                Deffinfo.Visble == newfinfo.Visble &&
                (newfinfo.IsSystemField == Deffinfo.IsSystemField && (Deffinfo.SpecialColor == newfinfo.SpecialColor && Deffinfo.SpecialString == newfinfo.SpecialString)))
                blnSameAsDefaultProperty = true;
            if (oldfinfo.Control != null && newfinfo.Control != null)
            {

                //if (oldfinfo.Control.Name.ToUpper().Trim() == "lblBranchNo".ToUpper())
                //{
                //    MsgBoxEx.Show("sdfs");
                //}
                if (oldfinfo.Control.Name != newfinfo.Control.Name ||
                    oldfinfo.BackColor != newfinfo.BackColor ||
                    oldfinfo.ForeColor != newfinfo.ForeColor ||
                    oldfinfo.DefaultValue != newfinfo.DefaultValue ||
                    oldfinfo.Enable != newfinfo.Enable ||
                    oldfinfo.Help != newfinfo.Help ||
                    oldfinfo.IsSystemField != newfinfo.IsSystemField ||
                    oldfinfo.Location != newfinfo.Location ||
                    oldfinfo.Size != newfinfo.Size ||
                    oldfinfo.Text != newfinfo.Text ||
                    oldfinfo.Visble != newfinfo.Visble ||
                    (newfinfo.IsSystemField && oldfinfo.IsSystemField && (oldfinfo.SpecialColor != newfinfo.SpecialColor || oldfinfo.SpecialString != newfinfo.SpecialString)))
                {

                    return true;
                }
            }
            return false;
        }
        private ControlAttribute GetOldContorlProptyInfo(string strControlName)
        {
            ControlAttribute oInfo = new ControlAttribute();
            foreach (ControlAttribute ofinfo in OldProperty)
            {
                if (ofinfo.Control.Name == strControlName)
                    return ofinfo;
            }
            return oInfo;
        }

        private ControlAttribute GetNewContorlProptyInfo(string strControlName)
        {
            ControlAttribute oInfo = new ControlAttribute();
            foreach (ControlAttribute ofinfo in NewProperty)
            {
                if (ofinfo.Control.Name == strControlName)
                    return ofinfo;
            }
            return oInfo;
        }
        private ControlAttribute GetDefControlProptyInfo(string strControlName)
        {
            ControlAttribute oInfo = new ControlAttribute();
            foreach (ControlAttribute ofinfo in DefProperty)
            {
                if (ofinfo.Control.Name == strControlName)
                    return ofinfo;
            }
            return oInfo;
        }
        private void GetOldAndDefaultProperty()
        {
            string strSql = "";
            DBAccess dbcon = new DBAccess(false, false);
            DataView dvStyle = null;
            strSql = "SELECT * FROM mnamedict where tableName ='" + mstrTable + "'";
            DataView dvDefStyle = dbcon.GetDataTable(strSql).DefaultView;

            strSql = @"SELECT syscolumns.name AS FieldName, systypes.name AS Type, syscolumns.length,replace(replace(replace(syscomments.text,'(',''),')',''),'''','') as DefValue
					FROM syscolumns INNER JOIN systypes ON syscolumns.xtype = systypes.xtype INNER JOIN
					sysobjects ON syscolumns.id = sysobjects.id INNER JOIN syscomments on syscomments.id=syscolumns.cdefault
					WHERE (systypes.status <> 1) AND (sysobjects.name = '{0}')";
            strSql = string.Format(strSql, mstrTable);

            DataView dvMaxLenAndDef = new DataView(dbcon.GetDataSet(strSql).Tables[0]);
            if (mstrCurrentStyle != "Default")
            {
                strSql = "SELECT * FROM mFormDict where UIStyle ='" + mstrCurrentStyle + "' and ProgName='" + mstrProgName + "' and Parameter=" + miParameter.ToString();
                dvStyle = dbcon.GetDataTable(strSql).DefaultView;
            }
            for (int i = 0; i < arraycontrols.Count; i++)
            {
                OldProperty[i].Control = arraycontrols[i] as Control;

                if (mstrCurrentStyle != "Default")
                {
                    dvStyle.RowFilter = "ControlName='" + OldProperty[i].Control.Name + "'";
                }
                DefProperty[i].Control = arraycontrols[i] as Control;
                DefProperty[i].Location = DefProperty[i].Control.Location;
                DefProperty[i].BackColor = DefProperty[i].Control.BackColor;
                DefProperty[i].ForeColor = DefProperty[i].Control.ForeColor;
                DefProperty[i].Size = DefProperty[i].Control.Size;
                DefProperty[i].Text = DefProperty[i].Control.Text;
                DefProperty[i].IsSystemField = false;
                DefProperty[i].SpecialColor = SystemColors.ControlText;
                DefProperty[i].SpecialString = "";
                DefProperty[i].Text = DefProperty[i].Control.Text;
                DefProperty[i].Help = "";
                DefProperty[i].DefaultValue = "";
                DefProperty[i].Visble = true;
                DefProperty[i].Enable = true;
                if (DefProperty[i].Control.GetType().Name == "TextBox" || DefProperty[i].Control.GetType().Name == "ComboBox" ||
                   DefProperty[i].Control.GetType().Name == "ComboBoxEx" || DefProperty[i].Control.GetType().Name == "DateTimeEx" ||
                   DefProperty[i].Control.GetType().Name == "TextRadioBox")
                {
                    dvMaxLenAndDef.RowFilter = "FieldName='" + DefProperty[i].Control.Name.Substring(3) + "'";
                    dvDefStyle.RowFilter = "FieldName='" + DefProperty[i].Control.Name.Substring(3) + "'";
                    if (dvDefStyle.Count > 0)
                    {
                        DefProperty[i].Help = CvtFunc.ToString(dvDefStyle[0]["Help"]);
                    }
                    if (dvMaxLenAndDef.Count > 0 && dvMaxLenAndDef[0]["DefValue"] != DBNull.Value && dvMaxLenAndDef[0]["DefValue"].ToString() != "")
                    {
                        DefProperty[i].DefaultValue = dvMaxLenAndDef[0]["DefValue"].ToString();
                    }
                }


                if (dvStyle != null && dvStyle.Count > 0)
                {
                    OldProperty[i].Location = new Point(CvtFunc.ToInt(dvStyle[0]["LocationX"]), CvtFunc.ToInt(dvStyle[0]["LocationY"]));
                    OldProperty[i].Size = new Size(CvtFunc.ToInt(dvStyle[0]["Width"]), CvtFunc.ToInt(dvStyle[0]["Height"]));
                    OldProperty[i].BackColor = Color.FromArgb(int.Parse(dvStyle[0]["BackColor"].ToString().Trim()  , System.Globalization.NumberStyles.AllowHexSpecifier));
                    OldProperty[i].ForeColor = Color.FromArgb(int.Parse(dvStyle[0]["ForeColor"].ToString().Trim()  , System.Globalization.NumberStyles.AllowHexSpecifier));
                    OldProperty[i].Visble = CvtFunc.ToBoolean(dvStyle[0]["Visibled"]);
                    OldProperty[i].Enable = CvtFunc.ToBoolean(dvStyle[0]["Enabled"]);
                    OldProperty[i].IsSystemField = CvtFunc.ToBoolean(dvStyle[0]["SystemField"]);
                    OldProperty[i].SpecialColor = Color.FromArgb(int.Parse(dvStyle[0]["SpecialColor"].ToString().Trim(), System.Globalization.NumberStyles.AllowHexSpecifier));
                    OldProperty[i].SpecialString = CvtFunc.ToString(dvStyle[0]["SpecialString"]);

                    OldProperty[i].Text = CvtFunc.ToString(dvStyle[0]["Text"]);
                    OldProperty[i].Help = CvtFunc.ToString(dvStyle[0]["ToolTip"]);
                    OldProperty[i].DefaultValue = CvtFunc.ToString(dvStyle[0]["ValueDefault"]);

                    OldProperty[i].Control.BackColor = OldProperty[i].BackColor;
                    OldProperty[i].Control.Size  = OldProperty[i].Size;
                    OldProperty[i].Control.Location  = OldProperty[i].Location;
                    OldProperty[i].Control.ForeColor  = OldProperty[i].ForeColor;
                    OldProperty[i].Control.Text  = OldProperty[i].Text;

                    if (OldProperty[i].Control.GetType().Name == "GroupBox" || OldProperty[i].Control.GetType().Name == "TabControl" || OldProperty[i].Control.GetType().Name == "TabPage" || OldProperty[i].Control.GetType().Name == "Panel")
                    {
                        foreach (Control con in OldProperty[i].Control.Controls)
                        {
                            if (con.GetType().Name == "Label")
                            {
                                con.ForeColor = OldProperty[i].Control.ForeColor;
                            }
                        }
                    }

                }
                else
                {
                    OldProperty[i].Location = OldProperty[i].Control.Location;
                    OldProperty[i].BackColor = OldProperty[i].Control.BackColor;
                    OldProperty[i].ForeColor = OldProperty[i].Control.ForeColor;
                    OldProperty[i].Size = OldProperty[i].Control.Size;
                    OldProperty[i].Text = OldProperty[i].Control.Text;
                    OldProperty[i].IsSystemField = false;
                    OldProperty[i].SpecialColor = SystemColors.ControlText;
                    OldProperty[i].SpecialString = "";
                    OldProperty[i].Text = OldProperty[i].Control.Text;
                    OldProperty[i].Help = "";
                    OldProperty[i].DefaultValue = "";
                    OldProperty[i].Visble = true;
                    OldProperty[i].Enable = true;
                    if (OldProperty[i].Control.GetType().Name == "TextBox" || OldProperty[i].Control.GetType().Name == "ComboBox" ||
                       OldProperty[i].Control.GetType().Name == "ComboBoxEx" || OldProperty[i].Control.GetType().Name == "DateTimeEx" ||
                       OldProperty[i].Control.GetType().Name == "TextRadioBox")
                    {
                        dvMaxLenAndDef.RowFilter = "FieldName='" + OldProperty[i].Control.Name.Substring(3) + "'";
                        dvDefStyle.RowFilter = "FieldName='" + OldProperty[i].Control.Name.Substring(3) +"'";
                        if (dvDefStyle.Count > 0)
                        {
                            OldProperty[i].Help = CvtFunc.ToString(dvDefStyle[0]["Help"]);
                        }
                        if (dvMaxLenAndDef.Count > 0 && dvMaxLenAndDef[0]["DefValue"] != DBNull.Value && dvMaxLenAndDef[0]["DefValue"].ToString() != "")
                        {
                            OldProperty[i].DefaultValue = dvMaxLenAndDef[0]["DefValue"].ToString();
                        }
                    }
                }
            }
            dbcon.CloseCon();  
        }


        private Control GetControl(Control conCurrent)
        {
            Control con = null;
            switch (conCurrent.GetType().Name)
            {

                case "WP.Controls.DataGridEx":
                    #region DataGridViewEx
                      DataGridEx dvgEx = new DataGridEx();
                      dvgEx.Text = (conCurrent as DataGridEx).Text;
                      con = dvgEx;
                    break;
                    #endregion
                case "DataGridView":
                    #region DataGridView
                    DataGridView dvg = new DataGridView();
                    dvg.Text = (conCurrent as DataGridView).Text;
                    con = dvg;
                    break;
                    #endregion
                case "Label":
                    #region label
                    Label lbl = new Label();
                    lbl.Text = (conCurrent as Label).Text;
                    lbl.TextAlign = (conCurrent as Label).TextAlign;
                    lbl.ForeColor = (conCurrent as Label).ForeColor;
                    lbl.BackColor = (conCurrent as Label).BackColor;
                    lbl.BorderStyle = (conCurrent as Label).BorderStyle;
                    
                    con = lbl;
                    break;
                    #endregion
                case "TextBox":
                    #region textbox
                    TextBox txt = new TextBox();
                    txt.Text = "";
                    txt.BorderStyle = (conCurrent as TextBox).BorderStyle;
                    txt.Multiline = (conCurrent as TextBox).Multiline;

                    con = txt;
                    break;
                    #endregion
                case "Button":
                    #region button
                    Button btn = new Button();
                    btn.Text = (conCurrent as Button).Text;
                    btn.FlatStyle = (conCurrent as Button).FlatStyle;
                    con = btn;
                    break;
                    #endregion

                case "MenuStrip":
                    #region MenuStrip
                    MenuStrip msp = new MenuStrip();
                    msp.Text = (conCurrent as MenuStrip).Text;
                    con = msp;
                    break;
                    #endregion
                case "ToolStrip":
                    #region ToolStrip
                    ToolStrip tsp = new ToolStrip();
                    tsp.Text = (conCurrent as ToolStrip).Text;
                    con = tsp;
                    break;
                    #endregion
                case "TableLayoutPanel":
                    #region TableLayoutPanel
                    TableLayoutPanel tnl = new TableLayoutPanel();
                    tnl.Text = (conCurrent as TableLayoutPanel).Text;
                    con = tnl;
                    tnl.RowCount = (conCurrent as TableLayoutPanel).RowCount;
                    tnl.ColumnCount = (conCurrent as TableLayoutPanel).ColumnCount;
                    tnl.RowStyles.Clear();
                    for (int i = 0; i < (conCurrent as TableLayoutPanel).RowStyles.Count; i++)
                    {
                        tnl.RowStyles.Add(new RowStyle());
                        tnl.RowStyles[i].SizeType = (conCurrent as TableLayoutPanel).RowStyles[i].SizeType;
                        tnl.RowStyles[i].Height = (conCurrent as TableLayoutPanel).RowStyles[i].Height;
                    }

                    tnl.ColumnStyles.Clear();
                    for (int i = 0; i < (conCurrent as TableLayoutPanel).ColumnStyles.Count; i++)
                    {
                        tnl.ColumnStyles.Add(new ColumnStyle());
                        tnl.ColumnStyles[i].SizeType = (conCurrent as TableLayoutPanel).ColumnStyles[i].SizeType;
                        tnl.ColumnStyles[i].Width = (conCurrent as TableLayoutPanel).ColumnStyles[i].Width;
                    }
                    break;
                    #endregion

                case "Panel":
                    #region panel
                    Panel pnl = new Panel();
                    pnl.Text = (conCurrent as Panel).Text;
                    pnl.Size = (conCurrent as Panel).Size;
                    pnl.Location = (conCurrent as Panel).Location;
                    con = pnl;
                    break;
                    #endregion
                case "GroupBox":
                    #region groupbox
                    GroupBox grp = new GroupBox();
                    grp.Text = (conCurrent as GroupBox).Text;
                    con = grp;
                    break;
                    #endregion
                case "ComboBox":
                    #region combobox
                    ComboBox cob = new ComboBox();
                    cob.Text = (conCurrent as ComboBox).Text;
                    con = cob;
                    break;
                    #endregion
                case "FlowLayoutPanel":
                    #region FlowLayoutPanel
                    FlowLayoutPanel flw = new FlowLayoutPanel();
                    con = flw;
                    break;
                    #endregion
                case "TabPage":
                    #region tabpage
                    TabPage tabpage = new TabPage();
                    tabpage.Text = (conCurrent as TabPage).Text;
                    con = tabpage;
                    break;
                    #endregion
                case "TabControl":
                    #region tabcontrol
                    TabControl tab = new TabControl();
                    tab.Text = (conCurrent as TabControl).Text;
                    con = tab;
                    break;
                    #endregion
                case "BindingNavigator":
                    #region BindingNavigator
                    BindingNavigator bdn = new BindingNavigator();
                    bdn.Text = (conCurrent as BindingNavigator).Text;
                    con = bdn;
                    break;
                    #endregion
                case "ButtonEx":
                    #region buttonEx
                    WP.Controls.ButtonEx ubt = new WP.Controls.ButtonEx();
                    ubt.Text = (conCurrent as WP.Controls.ButtonEx).Text;
                    ubt.FlatStyle = (conCurrent as WP.Controls.ButtonEx).FlatStyle;
                    ubt.ButtonImage = (conCurrent as WP.Controls.ButtonEx).ButtonImage;
                    ubt.ButtonImageSize = (conCurrent as WP.Controls.ButtonEx).ButtonImageSize;
                    ubt.ImageIndex = (conCurrent as WP.Controls.ButtonEx).ImageIndex;
                    con = ubt;
                    break;
                    #endregion
                case "ComboBoxEx":
                    #region comboboxex
                    WP.Controls.ComboBoxEx ucb = new WP.Controls.ComboBoxEx();
                    ucb.Text = (conCurrent as WP.Controls.ComboBoxEx).Text;
                    ucb.BorderStyle = (conCurrent as WP.Controls.ComboBoxEx).BorderStyle;
                    con = ucb;
                    break;
                    #endregion
                case "DateTimeEx":
                    #region datetimeEx
                    WP.Controls.DateTimeEx udt = new WP.Controls.DateTimeEx();
                    udt.Text = (conCurrent as WP.Controls.DateTimeEx).Text;
                    udt.BorderStyle = (conCurrent as WP.Controls.DateTimeEx).BorderStyle;
                    con = udt;
                    break;
                    #endregion
                case "TextRadioBox":
                    #region TextRadioBox
                    WP.Controls.TextRadioBox utr = new WP.Controls.TextRadioBox();
                    utr.Text = (conCurrent as WP.Controls.TextRadioBox).Text;
                    utr.BorderStyle = (conCurrent as WP.Controls.TextRadioBox).BorderStyle;
                    con = utr;
                    break;
                    #endregion
            }
            if (con != null)
            {
                con.Dock = conCurrent.Dock;
                con.Anchor = conCurrent.Anchor; 
                con.Name = (conCurrent as Control).Name;
                con.Margin = conCurrent.Margin;
                con.Size = conCurrent.Size; 
                return con;
            }
            else
                return null;
        }
        private void AddControl(Control conParent, Control conCurrent)
        {
            AddControl(conParent, conCurrent, -1, -1,-1,-1);
        }
        private void AddControl(Control conParent, Control conCurrent, int iRow, int iCol, int iRowSp, int iColSp)
        {

            Control con = GetControl(conCurrent);
            if (con != null)
            {
                con.Name = conCurrent.Name;
                con.BackColor = conCurrent.BackColor;
                con.ForeColor = conCurrent.ForeColor; 
                con.Visible = true;
                con.Anchor = conCurrent.Anchor;
                con.Location = conCurrent.Location;
                con.Size = conCurrent.Size;
                con.Parent = conParent;
                this.cboSeleControl.Items.Add(con.Name + " " + con.GetType().FullName);  
                if (iRow >= 0 && iCol >= 0)
                {
                    (conParent as TableLayoutPanel).Controls.Add(con, iCol, iRow);
                    (conParent as TableLayoutPanel).SetRowSpan(con, iRowSp);
                    (conParent as TableLayoutPanel).SetColumnSpan(con, iColSp);
                }
                if (conCurrent.GetType().Name == "TableLayoutPanel")
                {
                    //if (conCurrent.Name == "tableLayoutPanel1")
                    //{
                    //    MsgBoxEx.Show("Wait");
                    //}
                    for (int i = 0; i < (conCurrent as TableLayoutPanel).RowStyles.Count; i++)
                    {
                        for (int j = 0; j < (conCurrent as TableLayoutPanel).ColumnStyles.Count; j++)
                        {
                            Control conCurrentSub = (conCurrent as TableLayoutPanel).GetControlFromPosition(j, i);
                            if (conCurrentSub != null)
                            {
                                int iRowSpan = (conCurrent as TableLayoutPanel).GetRowSpan(conCurrentSub);
                                int iColSpan = (conCurrent as TableLayoutPanel).GetColumnSpan(conCurrentSub);
                                Control conSub = GetControl(conCurrentSub);

                                if (conSub!=null && !IncludeSubControl(con, conSub))
                                {
                                    (con as TableLayoutPanel).Controls.Add(conSub, j, i);
                                    (con as TableLayoutPanel).SetRowSpan(conSub, iRowSpan);
                                    (con as TableLayoutPanel).SetColumnSpan(conSub, iColSpan);
                                    if (conCurrentSub.Controls.Count > 0)
                                    {
                                        foreach (Control conSub1 in conCurrentSub.Controls)
                                        {
                                            if (conSub.GetType().Name == "TableLayoutPanel")
                                            {
                                                int iRowX = (conCurrentSub as TableLayoutPanel).GetPositionFromControl(conSub1).Row;
                                                int iColY = (conCurrentSub as TableLayoutPanel).GetPositionFromControl(conSub1).Column;

                                                int iRowSpanX = (conCurrentSub as TableLayoutPanel).GetRowSpan(conSub1);
                                                int iColSpanY = (conCurrentSub as TableLayoutPanel).GetColumnSpan(conSub1);
                                                AddControl(conSub, conSub1, iRowX, iColY, iRowSpanX, iColSpanY);
                                            }
                                            else
                                            {
                                                AddControl(conSub, conSub1);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        conSub.MouseDown += new MouseEventHandler(this.Control_MouseDown);
                                        arraycontrols.Add(conSub); 
                                    }
                                }
                            }
                        }
                    }
                }

                if (conCurrent.GetType().Name == "ToolStrip")
                {
                    foreach (ToolStripItem oItem in (conCurrent as ToolStrip).Items)
                    {
                        ToolStripItem o1 = GetToolStripItem(oItem); 
                        if(o1!=null) (con as ToolStrip).Items.Add(o1 );    
                    }
                }

                if (conCurrent.GetType().Name == "MenuStrip")
                {
                    
                    foreach ( ToolStripMenuItem  menuItem in (conCurrent as MenuStrip).Items)
                    {
                        ToolStripItem o1 = GetToolStripMenuItem(menuItem);
                        if (o1 != null) (con as MenuStrip).Items.Add(o1);
                    }

                }
                if (conCurrent.GetType().Name != "ToolStrip" && conCurrent.GetType().Name != "MenuStrip")
                {
                    //if (conCurrent.GetType().Name == "TextRadioBox")
                    //{
                    //    MsgBoxEx.Show("sdfsfd");
  
                    //}
                    con.MouseDown += new MouseEventHandler(this.Control_MouseDown);
                }
               arraycontrols.Add(con); 
            }

            if (conCurrent.Controls.Count > 0 && con != null && conCurrent.GetType().Name != "TableLayoutPanel")
            {

                foreach (Control conSub in conCurrent.Controls)
                {
                    AddControl(con, conSub);
                }
            }
        }

        private ToolStripMenuItem GetToolStripMenuItem(ToolStripMenuItem oItem)
        {
            ToolStripMenuItem tItem = null;
            switch (oItem.GetType().Name)
            {
                case "ToolStripMenuItem":
                    ToolStripMenuItem s = new ToolStripMenuItem();
                    s.Image = oItem.Image;
                    s.Text = oItem.Text;
                    s.Alignment = oItem.Alignment;
                    s.TextImageRelation = oItem.TextImageRelation;
                    s.DisplayStyle = oItem.DisplayStyle;
                    s.ImageScaling = oItem.ImageScaling;
                    tItem = s;
                    break;

            }
            if (tItem != null)
                return tItem;
            else
                return null;


        }

        private ToolStripItem GetToolStripItem(ToolStripItem oItem)
        {
            ToolStripItem tItem=null;
            switch (oItem.GetType().Name)
            {
                case "ToolStripButton" :
                    ToolStripButton t = new ToolStripButton();
                    t.Image = oItem.Image;
                    t.Text = oItem.Text;
                    t.Alignment = oItem.Alignment;
                    t.TextImageRelation = oItem.TextImageRelation;
                    t.DisplayStyle = oItem.DisplayStyle;
                    t.ImageScaling = oItem.ImageScaling;
                    tItem = t;
                    break;
                case "ToolStripSeparator":
                    ToolStripSeparator s = new ToolStripSeparator();
                    s.Image = oItem.Image;
                    s.Text = oItem.Text;
                    s.Alignment = oItem.Alignment;
                    s.TextImageRelation = oItem.TextImageRelation;
                    s.DisplayStyle = oItem.DisplayStyle;
                    s.ImageScaling = oItem.ImageScaling;
                    tItem = s;
                    break;
                case "ToolStripSplitButton" :
                    ToolStripSplitButton s1 = new ToolStripSplitButton();
                    s1.Image = oItem.Image;
                    s1.Text = oItem.Text;
                    s1.Alignment = oItem.Alignment;
                    s1.TextImageRelation = oItem.TextImageRelation;
                    s1.DisplayStyle = oItem.DisplayStyle;
                    s1.ImageScaling = oItem.ImageScaling;
                    tItem = s1;
                    break;
                case "ToolStripLabel":
                    ToolStripLabel s2 = new ToolStripLabel();
                    s2.Image = oItem.Image;
                    s2.Text = oItem.Text;
                    s2.Alignment = oItem.Alignment;
                    s2.TextImageRelation = oItem.TextImageRelation;
                    s2.DisplayStyle = oItem.DisplayStyle;
                    s2.ImageScaling = oItem.ImageScaling;
                    tItem = s2;
                    break;

            }
            if(tItem!=null)
               return tItem ;
            else 
               return null ;


        }


        private bool IncludeSubControl(Control cParent,Control cChild)
        {
            foreach (Control con in cParent.Controls)
            {
                if (cChild.Name == con.Name) return true;  
            }
            return false;
        }

        private void Control_MouseDown(object sender, MouseEventArgs e)
        {
            Control con = sender as Control;
            if (con != null)
            {
                mCurrentControl = con;
                ReleaseCapture();
                SendMessage(con.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
                ControlAttribute fNewProp = GetNewContorlProptyInfo(mCurrentControl.Name);
                if (fNewProp.Control != null)
                {
                    fNewProp.Location = mCurrentControl.Location;
                    conProperty.SelectedObject = fNewProp;
                }
                if (cboSeleControl.Text != con.GetType().FullName)
                {
                    cboSeleControl.Text = con.Name + " " + con.GetType().FullName;
                }
            }



        }

        private void splitterWidth_SplitterMoved(object sender, SplitterEventArgs e)
        {
            pnlRight.Left = splitterWidth.Left + splitterWidth.Width;      
        }

        private void pnlRight_Enter(object sender, EventArgs e)
        {
            lblProp.BackColor = SystemColors.Highlight ;
            lblProp.ForeColor = Color.White; 
        }

        private void pnlRight_Leave(object sender, EventArgs e)
        {
            lblProp.BackColor = SystemColors.InactiveCaptionText;
            lblProp.ForeColor = Color.Black ; 
        }





        private void tbnSave_Click(object sender, EventArgs e)
        {
            string strStyleName = "", strSql = ""; ;
            if (!ConfirmChanged())
            {
                MsgBoxEx.Show(Msg.Select("Not any change.", DataFunctions.GetMsg(this.Name, "MSG_NotAnyChange")), SysVar.WarnTitle);  
                return;
            }
            DBAccess dbcon = new DBAccess(false, false);
            try
            {
                if (mstrCurrentStyle == "Default")
                {
                    while (true)
                    {
                        frmInput frmIn = new frmInput();
                        strStyleName = frmIn.InputData("Please Enter Style Name", SysVar.WarnTitle, "", "Style Name can not be empty.", "", "");
                        if (DataFunctions.CheckRecordExist("mFormDict", strStyleName, "UIStyle", "Progname='" + mstrProgName + "' and Parameter=" + miParameter.ToString()))
                        {
                            if (MsgBoxEx.Show(Msg.Select("The Style file already on file. Do you want to replace it?", DataFunctions.GetMsg(this.Name, "MSG_StyleFileAlreadyOnFile")), SysVar.WarnTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    strStyleName = mstrCurrentStyle;
                }
                dbcon.BeginTran();

                DataTable dtTable = dbcon.GetDataTable("select top 0 * from " + mstrTable);
                foreach (Control con in arraycontrols)
                {
                    bool blnSameAsDefaultProperty = false;
                    if (ControlPropertyChanged(con, out blnSameAsDefaultProperty))
                    {
                        string strFieldName = GetFieldName(dtTable, con);  
                        strSql = "delete from mFormDict where ControlName='" + con.Name +"' and progname='" + mstrProgName + "' and Parameter=" + miParameter.ToString() + " and UIStyle ='" + strStyleName.Replace("'", "''") + "'";
                        dbcon.ExecuteSql(strSql);
                        if (!blnSameAsDefaultProperty)
                        {
                            ControlAttribute newProp = GetNewContorlProptyInfo(con.Name);
                            strSql = "Insert into mFormDict (TableName,UIStyle,FieldName,ControlName,Text,SystemField,SpecialString,SpecialColor,Visibled,Enabled,LocationX,LocationY,Width,Height,ToolTip," +
                                     "ValueDefault,ProgName,Parameter,BackColor,ForeColor) values (" +
                                     "'" + mstrTable + "','" + strStyleName + "','" + strFieldName + "','" + con.Name + "','" + newProp.Control.Text.Replace("'", "''") + "'," +
                                     (newProp.IsSystemField ? "1" : "0") + ",'" + newProp.SpecialString.Replace("'", "''") + "','" + newProp.SpecialColor.ToArgb().ToString("x") + "'," + (newProp.Visble ? "1" : "0") + "," + (newProp.Enable ? "1" : "0") + "," + newProp.Location.X.ToString() + "," + newProp.Location.Y.ToString() +
                                     "," + newProp.Size.Width.ToString() + "," + newProp.Size.Height.ToString() + ",'" + newProp.Help.Replace("'", "''") + "','" + newProp.DefaultValue.Replace("'", "''") + "','" +
                                      mstrProgName.Replace("'", "''") + "'," + miParameter.ToString() + ",'" + newProp.BackColor.ToArgb().ToString("x") + "','" + newProp.ForeColor.ToArgb().ToString("x") + "')";
                            dbcon.ExecuteSql(strSql);
                        }
                        ControlAttribute newfinfo = GetNewContorlProptyInfo(con.Name);
                        for (int i = 0; i < OldProperty.Length; i++)
                        {
                            if (OldProperty[i].Control.Name == con.Name)
                            {
                                OldProperty[i] = newfinfo;
                                break;
                            }
                        }
                    }
                }
                if (!DataFunctions.CheckRecordExist(dbcon, "mFormDict", mstrProgName, "progname", "Parameter=" + miParameter.ToString() + " and UIStyle ='" + strStyleName.Replace("'", "''") + "'"))
                {
                    strSql = "delete from mUIUserStyle where progname='" + mstrProgName + "' and Parameter=" + miParameter.ToString() + " and UIStyle ='" + strStyleName.Replace("'", "''") + "'";
                    dbcon.ExecuteSql(strSql);
                    this.Status = FormStatus.AddNew; 
                }

                dbcon.CommitTran();
                dbcon.CloseCon();
                mstrCurrentStyle = strStyleName;
              //  this.Text = "User Interface Design" + " - [" +  this.MdiChildren[0].Text + "] - [" + (mstrCurrentStyle == "Default" ? "Untitled1" : mstrCurrentStyle) + "]";
            }
            catch (Exception x)
            {
                dbcon.RollbackTran();
                dbcon.CloseCon();
                MsgBoxEx.Show(x.Message);   
            }
        }



        private string GetFieldName(DataTable dtTable,Control con)
        {
            if (con.GetType().Name == "TextBox" || con.GetType().Name == "ComboBox" || 
                con.GetType().Name == "ComboBoxEx" || con.GetType().Name =="DateTimeEx" || con.GetType().Name=="TextRadioBox" )
            {
                string strFieldName = con.Name.Substring(3).Trim() ;
                for (int i = 0; i < dtTable.Columns.Count; i++)
                {
                    if (dtTable.Columns[i].Caption.ToUpper().Trim() == strFieldName.ToUpper().Trim())
                    {
                        return strFieldName.ToUpper().Trim();
                    }
                }
            }
            return "";
        }


        private void tbnDel_Click(object sender, EventArgs e)
        {
            if (MsgBoxEx.Show(Msg.Select("Are you sure you want to delete the style file " + mstrCurrentStyle + "?", DataFunctions.GetMsg(this.Name, "MSG_DeleteTheStyleFile", new string[] { mstrCurrentStyle })), SysVar.WarnTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;  
            DBAccess dbcon = new DBAccess(false, false);
            string strSql = "delete from mUIUserStyle where progname='" + mstrProgName + "' and Parameter=" + miParameter.ToString() + " and UIStyle ='" + mstrCurrentStyle.Replace("'", "''") 
                         + "';  delete from mFormDict where progname='" + mstrProgName + "' and Parameter=" + miParameter.ToString() + " and UIStyle ='" + mstrCurrentStyle.Replace("'", "''") + "'";
            dbcon.ExecuteSql(strSql);
            dbcon.CloseCon();
            this.Status = FormStatus.Delete; 
        }

        private void tbnOpen_Click(object sender, EventArgs e)
        {
            string strTable = "";
            frmUIOpenAndNewDailg frmDlg = new frmUIOpenAndNewDailg();
            string strMenuID = (mCurrentMenuInfo.strMenuId == null ? "" : mCurrentMenuInfo.strMenuId);
            string strSelectStyle = frmDlg.SelectDesignStyle(ref strMenuID);
            if (strSelectStyle.Trim() != "")
            {
                MenuInfo menuInfo = DataFunctions.GetMenuInfo(strMenuID);
                SetUI(menuInfo, strTable, strSelectStyle);
                this.Status = FormStatus.Update;
            }
        }

        private void tbnNew_Click(object sender, EventArgs e)
        {
            frmUIOpenAndNewDailg frmDlg = new frmUIOpenAndNewDailg();
            string strMenuId = frmDlg.SelectMenuId(mCurrentMenuInfo.strMenuId);
            if (strMenuId != "")
            {
                MenuInfo  menuInfo = DataFunctions.GetMenuInfo(strMenuId);
                SetUI(menuInfo , "", "");
                this.Status = FormStatus.AddNew ;
            }
        }

        private void tbnUserStyle_Click(object sender, EventArgs e)
        {
            if (mstrProgName.Trim() != "")
            {
                frmUIUserStyle frmUserStyle = new frmUIUserStyle();
                frmUserStyle.SetUserStyle(mstrProgName, miParameter);   
            }
        }



        private void frmUIDesign_Load(object sender, EventArgs e)
        {

        }

        private void FileMenu_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mnuItem = sender as ToolStripMenuItem;
            if (mnuItem != null)
            {
                switch (mnuItem.Name)
                {
                    case "newToolStripMenuItem":
                        tbnNew_Click(sender, e);
                        break;
                    case "openToolStripMenuItem":
                        tbnOpen_Click(sender, e);
                        break;
                    case "deleteToolStripMenuItem":
                        tbnDel_Click(sender, e);
                        break;
                    case "saveToolStripMenuItem":
                        tbnSave_Click(sender, e);
                        break;
                    case "exitToolStripMenuItem":
                        tbnExit_Click(sender, e);
                        break;
                }
            }
        }

        private void ActionMenu_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mnuItem = sender as ToolStripMenuItem;
            if (mnuItem != null)
            {
                switch (mnuItem.Name)
                {

                    case "userStyleToolStripMenuItem":
                        tbnUserStyle_Click(sender, e);
                        break;

                }
            }
        }
        private void ChildForm_Closed(object sender, FormClosedEventArgs e)
        {

            if (this.MdiChildren.Length == 1)
            {
                this.pnlRight.Width = 0;
                this.tbnSave.Enabled = false;
                this.saveToolStripMenuItem.Enabled = false;
                this.userStyleToolStripMenuItem.Enabled = false;
                this.tbnUserStyle.Enabled = false; 
            }
            else
            {
                
                this.pnlRight.Width = 281;
            }

        }
        private void frmUIDesign_FormClosed(object sender, FormClosedEventArgs e)
        {

        }

        private void cboSeleControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            Control ConSele = null;
            foreach (Control con in this.arraycontrols)
            {
                if (con.Name == this.cboSeleControl.Text.Substring(0, this.cboSeleControl.Text.IndexOf(" ")))
                {
                    ConSele = con;
                }
            }
            if (ConSele != null)
            {
                Control_MouseDown(ConSele, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));   
            }
        }




        private class ControlAttribute
        {
            private Control mControl;
            private Point mLocation;
            private Size mSize;
            private bool mVisble;
            private bool mEnable;
            private bool mIsSystemField;
            private string mSpecialString;
            private Color mSpecialColor;
            private string mText;
            private string mHelp;
            private string mDefaultValue;
            private Color mBackcolor;
            private Color mForecolor;


            [ReadOnlyAttribute(true), BrowsableAttribute(false )]
            public Control Control
            {
                get { return mControl; }
                set { mControl = value; }
            }

            [CategoryAttribute("Color")]
            public Color BackColor
            {
                get { return mBackcolor; }
                set { mBackcolor = value; }
            }

            [CategoryAttribute("Color")]
            public Color ForeColor
            {
                get { return mForecolor; }
                set { mForecolor = value; }
                 
            }
            [DescriptionAttribute("Set label control prompt.")]
            public string Text
            {
                get { return mText; }
                set { mText = value; }
            }
            public string Help
            {
                get { return mHelp; }
                set { mHelp = value; }
            }
            [DescriptionAttribute("Set edit control default value.")]
            public string DefaultValue
            {
                get { return mDefaultValue; }
                set { mDefaultValue = value; }
            }
            public Point Location
            {
                get { return mLocation; }
                set { mLocation = value; }
            }
            public Size Size
            {
                get { return mSize; }
                set { mSize = value; }
            }
            public bool Visble
            {
                get { return mVisble; }
                set { mVisble = value; }
            }
            public bool Enable
            {
                get { return mEnable; }
                set { mEnable = value; }
            }

            [CategoryAttribute("System Field")]
            public bool IsSystemField
            {
                get { return mIsSystemField; }
                set { mIsSystemField = value; }
            }
            [CategoryAttribute("System Field")]
            public Color SpecialColor
            {
                get { return mSpecialColor; }
                set { mSpecialColor = value; }
            }
            [CategoryAttribute("System Field")]
            public string  SpecialString
            {
                get { return mSpecialString; }
                set { mSpecialString = value; }
            }


        }

        private void conProperty_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {

            ControlAttribute oAttribute = conProperty.SelectedObject as ControlAttribute;
            if (oAttribute != null)
            {

                mCurrentControl.Location = oAttribute.Location;
                mCurrentControl.BackColor = oAttribute.BackColor;
                mCurrentControl.ForeColor = oAttribute.ForeColor ;
                mCurrentControl.Size = oAttribute.Size;
                mCurrentControl.Text = oAttribute.Text;
                for (int i = 0; i < NewProperty.Length; i++)
                {
                    if (NewProperty[i].Control.Name == mCurrentControl.Name)
                    {
                        NewProperty[i].BackColor = oAttribute.BackColor;
                        NewProperty[i].ForeColor = oAttribute.ForeColor;
                        NewProperty[i].Location = oAttribute.Location;
                        NewProperty[i].Size = oAttribute.Size;
                        NewProperty[i].Text = oAttribute.Text;
                        NewProperty[i].Visble = oAttribute.Visble;
                        NewProperty[i].IsSystemField = oAttribute.IsSystemField;
                        NewProperty[i].Enable = oAttribute.Enable;
                        NewProperty[i].DefaultValue = oAttribute.DefaultValue;
                        NewProperty[i].Help = oAttribute.Help;
                        NewProperty[i].SpecialString = oAttribute.SpecialString;
                        NewProperty[i].SpecialColor = oAttribute.SpecialColor;
                        if (!NewProperty[i].IsSystemField)
                        {
                            NewProperty[i].SpecialString = "";
                            NewProperty[i].SpecialColor = SystemColors.ControlText;
                        }
                        break;
                    }
                }
                if (mCurrentControl.GetType().Name == "GroupBox" || mCurrentControl.GetType().Name == "TabControl" || mCurrentControl.GetType().Name == "TabPage" || mCurrentControl.GetType().Name == "Panel")
                {
                    foreach (Control con in mCurrentControl.Controls)
                    {
                        if (con.GetType().Name == "Label")
                        {
                            con.ForeColor = mCurrentControl.ForeColor;
                        }
                    }
                }
            }
        }


    }
}